package com.yq.design.iterator;

import java.util.Iterator;
import java.util.List;

/**
 * @ClassName Output
 * @Description TODO
 * @Author yaoqiang
 * @Date 2021/8/24 14:16
 * @Version 1.0
 */
public class Output {

    List<College> colleges;

    public Output(List<College> colleges) {
        this.colleges = colleges;
    }
    //遍历所有系
    public void printDepartment(Iterator iterator){
        while (iterator.hasNext()){
            Department department= (Department) iterator.next();
            System.out.println(department);
        }
    }
    //遍历college，每个collge调用printDepartment遍历系

    public void printCollege(){
        Iterator<College> iterator=colleges.iterator();
        while ( iterator.hasNext()){
            //取出一个college
            College college=iterator.next();
            System.out.println("-------"+college.getName()+"----------");
            printDepartment(college.createIterator());
        }
    }

}
